<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");

$arrWeb = explode(",", $_data["AllWeb"]);
$GameDate = (empty($_data["GameDate"]))?date("Y-m-d"):$_data["GameDate"];
$GameTime1 = (empty($_data["GameTime1"]))?"00:00:00":$_data["GameTime1"];
$GameTime2 = (empty($_data["GameTime2"]))?"24:00:00":$_data["GameTime2"];
$intSortType = (int)$_data["SortType"];

if(!get_magic_quotes_gpc()){
	$GameDate = addslashes($GameDate);
	$GameTime1 = addslashes($GameTime1);
	$GameTime2 = addslashes($GameTime2);
}
if($GameTime1 > $GameTime2){
	$strTmp = $GameTime1;
	$GameTime1 = $GameTime2;
	$GameTime2 = $strTmp;
}

$strTmp1 = "<tr class=\"clef\"> 
	<td align='center'>{No}</td>
	<td align='left'>{Web}</td>
	<td align='right'><!--WagerNo//-->0</td>
	<td align='right'><!--WagerMoney//-->0</td>
	<td align='right'><!--StockResult//-->0</td>
</tr>";

$intTotalN = 0;
$intTotalM = 0;
$flTotalR = 0;
$arrDB = array();
$strCon = "";
$arrCon = array();
$arrKey = array();
$arrSort = array();
$intNo = 0;
foreach($arrWeb as $strWeb){
	$arrDN = explode("@", $strWeb);
	$strDN = $arrDN[0];
	$strDomain = $strDN;
	//$strDName = $arrDN[1];
	include("/home/share/www/".$arrDN[1]."/secure/db.inc.php");

	$strTmp2 = $strTmp1;
	$strTmp2 = str_replace("{Web}", $strDomain." -- {".$strDomain."} &nbsp;(".$_blDBHostM.")", $strTmp2);
	$intNo++;
	$strTmp2 = str_replace("{No}", $intNo, $strTmp2);

	$strSQL = "select COUNT(*) as WagerNo, SUM(a.MemStake) as WagerMoney, SUM(a.DirectorRateResult) as DirectorResult from `bet_BetList` a, `bet_BetListContent` b where a.PayupDate = '".$GameDate."' and a.isPayOff = 0 and a.ID = b.ID and (b.BetTime between '".$GameTime1."' and '".$GameTime2."')";
	//print $strSQL."<br>\n";
	$RS = @PMA_mysql_query($strSQL, $$_Conn);
	while($Rows = PMA_mysql_fetch_object($RS)){
		$strTmp2 = str_replace("<!--WagerNo//-->0", number_format($Rows -> WagerNo*1), $strTmp2);
		$strTmp2 = str_replace("<!--WagerMoney//-->0", number_format($Rows -> WagerMoney*1), $strTmp2);
		$strTmp2 = str_replace("<!--StockResult//-->0", number_format($Rows -> DirectorResult*1,2,'.',','), $strTmp2);
		$intTotalN += $Rows -> WagerNo;
		$intTotalM += $Rows -> WagerMoney;
		$flTotalR += $Rows -> DirectorResult;
		$arrKey[$intNo] = $intNo;
		switch($intSortType){
			case 1:
				$arrSort[$intNo] = $Rows -> WagerNo;
				break;

			case 2:
				$arrSort[$intNo] = $Rows -> WagerMoney;
				break;

			case 3:
				$arrSort[$intNo] = $Rows -> DirectorResult;
				break;

			default:
				$arrSort[$intNo] = $intNo;
				break;
		}
	}
	$arrCon[$intNo] = $strTmp2;
	@mysql_free_result($RS);
	@mysql_close($$_Conn);
}
array_multisort($arrSort, $arrKey);

$arrCon2 = array();
foreach($arrSort as $k => $v){
	$arrCon2[] = $arrCon[$arrKey[$k]];
}
$strCon = implode("", $arrCon2);

$strTmp2 = str_replace("{Web}", "Sum", $strTmp1);
$strTmp2 = str_replace("{No}", "", $strTmp2);
$strTmp2 = str_replace("<!--WagerNo//-->0", number_format($intTotalN), $strTmp2);
$strTmp2 = str_replace("<!--WagerMoney//-->0", number_format($intTotalM), $strTmp2);
$strTmp2 = str_replace("<!--StockResult//-->0", number_format($flTotalR,2,'.',','), $strTmp2);
$strCon .= $strTmp2;
?>
<table width="765" border="0" cellspacing="1" cellpadding="0" class="ctab">
<tr class="ctiga">
	<td width="50">序號</td>
	<td width="150">網站</td>
	<td width="120">注單數</td>
	<td width="120">總金額</td>
	<td width="120">總監結果</td>
</tr>
<?php print $strCon;?>
<tr class="ctiga">
	<td colspan="5">
現在時間：<?php print date("Y-m-d H:i:s");?>
	</td>
</tr>
</table>
